package com.xiaoyushu.user.relation.biz.rpc;


import cn.hutool.core.collection.CollUtil;
import com.xiaoyushu.framework.common.response.Response;
import com.xiaoyushu.user.api.UserFeignApi;
import com.xiaoyushu.user.dto.req.FindUserByIdReqDTO;
import com.xiaoyushu.user.dto.req.FindUsersByIdsReqDTO;
import com.xiaoyushu.user.dto.resp.FindUserByIdRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 用户服务
 */
@Component
public class UserRpcService {

    @Resource
    private UserFeignApi userFeignApi;

    public FindUserByIdRspDTO findById(Long userId) {
        FindUserByIdReqDTO findUserByIdReqDTO = new FindUserByIdReqDTO();
        findUserByIdReqDTO.setId(userId);
        Response<FindUserByIdRspDTO> byId = userFeignApi.findById(findUserByIdReqDTO);
       if (!byId.isSuccess()|| Objects.isNull(byId.getData())){
           return null;
       }
       return byId.getData();
    }

    public List<FindUserByIdRspDTO> findByIds(List<Long> userIds){

        FindUsersByIdsReqDTO findUsersByIdsReqDTO= new FindUsersByIdsReqDTO();
        findUsersByIdsReqDTO.setIds(userIds);

        Response<List<FindUserByIdRspDTO>> response=userFeignApi.findByIds(findUsersByIdsReqDTO);

        if (!response.isSuccess()||Objects.isNull(response.getData()) || CollUtil.isEmpty(response.getData()))
        {
            return null;
        }
        return response.getData();
    }
}
